import 'package:flutter/material.dart';
import 'package:vdrag_saas/Utils.dart';
import 'package:vdrag_saas/model/item_model.dart';
import 'package:vdrag_saas/list/pages/home/components/item_content_row.dart';
import 'package:vdrag_saas/list/pages/home/components/item_content_colomn.dart';
import 'package:vdrag_saas/detail/detail.dart';

class ItemTile extends StatefulWidget {
  Function() onBack;
  final ItemModel item;
  ItemTile({
    super.key,
    required this.item,
    required this.onBack
  });

  @override
  State<ItemTile> createState() => _ItemTile();
}

class _ItemTile extends State<ItemTile> {
  bool isMobile = false;

  @override
  Widget build(BuildContext context) {
    // Size screenSize = MediaQuery.of(context).size;
    // double screenWidth = screenSize.width;
    // isMobile = DeviceUtil.isMobile || screenWidth < 600;
    bool isMobile = Utils.isMobile(context);
    double screenWidth = MediaQuery.of(context).size.width;
    // Stack 可以容纳多个组件，以叠加的方式摆放子组件，后者居上。拥有Alignment属性，
    // 可以与Positioned组件联合使用，精准并有效摆放。同Android端FramLayout布局相似。
    return Stack(
      children: [
        const Padding(padding: EdgeInsetsDirectional.only(end: 0)),
        // GestureDetector  手势识别组件
        GestureDetector(
          behavior: HitTestBehavior.translucent,
            // 点击事件回调
            onTap: () {
              Navigator.of(context).push(MaterialPageRoute(builder: (c) {
                return Detail(id: widget.item.id!, onBack: widget.onBack,);
              }));
            },
            // child: Container(width: screenWidth, color: Colors.red, height: 40),
            child: isMobile
                ? ItemContentRow(item: widget.item, width: screenWidth)
                : ItemContentColumn(item: widget.item)
          ),
      ],
    );
  }
}
